package com.gxa.saas.portal.controller;

import com.gxa.saas.core.vo.GoodsVo;
import com.gxa.saas.portal.service.GoodsHomepageService;
import com.gxa.saas.portal.service.JestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "c端首页模块")
@Controller
public class GoodsHomepageController {

    @Autowired
    private JestService jestService;

    @Autowired
    private GoodsHomepageService goodsHomepageService;

    @ApiOperation("轮播图")
    @ResponseBody
    @GetMapping("/GoodsHomepage/slideshow")
    public Map slideshow(){
        Map map = new HashMap();
         map = this.goodsHomepageService.selectSlideshow();
        return map;
    }

    @ApiOperation("商品分类")
    @ResponseBody
    @GetMapping("/GoodsHomepage/classify")
    public Map classify(){
        Map map = new HashMap();
        map = this.goodsHomepageService.goodsClassify();
         if (MapUtils.isEmpty(map)){
             map.put("code","300");
             map.put("message","无数据");
             return map;
         }
        return map;
    }

    @ApiOperation("热销商品")
    @ResponseBody
    @GetMapping("/GoodsHomepage/hotGoods")
    public Map hotGoods(){
        Map map = new HashMap();
         map = this.goodsHomepageService.selectHotGoods();
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;
    }

    @ApiOperation("综合商品")
    @ResponseBody
    @GetMapping("/GoodsHomepage/synthesisGoods")

    public Map synthesisGoods(@RequestParam Integer pageNumber,@RequestParam Integer pageSize){
        Map map = new HashMap();
        if (pageNumber==null){
            map.put("code",400);
            map.put("message","pageNumber参数错误");
            return map;
        }
        if (pageSize==null){
            map.put("code",400);
            map.put("message","pageSize参数错误");
            return map;
        }
        map = this.jestService.searchSynthesisGoods(pageNumber, pageSize);
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;
    }

    @ApiOperation("按价格排序商品")
    @ResponseBody
    @GetMapping("/GoodsHomepage/priceGoods")
    public Map priceGoods(@RequestParam("value") Integer value,@RequestParam Integer pageNumber,@RequestParam Integer pageSize){
        Map map = new HashMap();
        if (pageNumber==null){
            map.put("code",400);
            map.put("message","pageNumber参数错误");
            return map;
        }
        if (pageSize==null){
            map.put("code",400);
            map.put("message","pageSize参数错误");
            return map;
        }
        if (value==null){
            map.put("code",400);
            map.put("message","value参数错误");
            return map;
        }
        map =  this.jestService.searchpriceGoods(pageNumber,pageSize,value);
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;
    }

    @ApiOperation("按销量排序商品")
    @ResponseBody
    @GetMapping("/GoodsHomepage/salesGoods")
    public Map salesGoods(@RequestParam("value") Integer value,@RequestParam Integer pageNumber,@RequestParam Integer pageSize){
        Map map = new HashMap();
        if (pageNumber==null){
            map.put("code",400);
            map.put("message","pageNumber参数错误");
            return map;
        }
        if (pageSize==null){
            map.put("code",400);
            map.put("message","pageSize参数错误");
            return map;
        }
        if (value==null){
            map.put("code",400);
            map.put("message","value参数错误");
            return map;
        }
        map = this.jestService.searcheSalesGoods(pageNumber,pageSize,value);
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;
    }

    @ApiOperation("搜索商品")
    @GetMapping(value = "/GoodsHomepage/searchGoods")
    @ResponseBody
    public Map searchGoods(@RequestParam String keyword,@RequestParam Integer pageNumber,@RequestParam Integer pageSize){
        Map map = new HashMap();
        if (pageNumber==null){
            map.put("code",400);
            map.put("message","pageNumber参数错误");
            return map;
        }
        if (pageSize==null){
            map.put("code",400);
            map.put("message","pageSize参数错误");
            return map;
        }
        if (StringUtils.isEmpty(keyword)){
            map.put("code",400);
            map.put("message","keyword参数错误");
            return map;
        }
        map =  jestService.search(keyword,pageNumber,pageSize);
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;

    }


}
